import request from '@/config/axios'
import {BankVO} from "@/api/exam/bank";

// 用户-题库 VO
export interface UserBankVO {
  id: number // 主键
  bankId: number // 题库ID
  userId: number // 持有者
  expireTime: Date // 过期时间
  source: string // 题库来源
}

export interface MemberUserBankVO extends UserBankVO{
  bankResp: BankVO
}

// 用户-题库 API
export const UserBankApi = {
  // 查询用户-题库分页
  getUserBankPage: async (params: any) => {
    return await request.get({ url: `/exam/user-bank/page`, params })
  },
  // 查询用户-题库分页
  getMemberUserBankPage: async (params: any) => {
    return await request.get({ url: `/exam/user-bank/member/page`, params })
  },
  // 查询试题分页
  getMemberQuestionList: async (params: any) => {
    return await request.get({ url: `/exam/user-bank/member/question/list`, params })
  },
  // 查询用户-题库详情
  getUserBank: async (id: number) => {
    return await request.get({ url: `/exam/user-bank/get?id=` + id })
  },

  // 新增用户-题库
  createUserBank: async (data: UserBankVO) => {
    return await request.post({ url: `/exam/user-bank/create`, data })
  },

  // 修改用户-题库
  updateUserBank: async (data: UserBankVO) => {
    return await request.put({ url: `/exam/user-bank/update`, data })
  },

  // 删除用户-题库
  deleteUserBank: async (id: number) => {
    return await request.delete({ url: `/exam/user-bank/delete?id=` + id })
  },

  // 导出用户-题库 Excel
  exportUserBank: async (params) => {
    return await request.download({ url: `/exam/user-bank/export-excel`, params })
  },

// ==================== 子表（用户-题库-记录） ====================

  // 获得用户-题库-记录分页
  getUserBankRecordPage: async (params) => {
    return await request.get({ url: `/exam/user-bank/user-bank-record/page`, params })
  },
  // 新增用户-题库-记录
  createUserBankRecord: async (data) => {
    return await request.post({ url: `/exam/user-bank/user-bank-record/create`, data })
  },

  // 修改用户-题库-记录
  updateUserBankRecord: async (data) => {
    return await request.put({ url: `/exam/user-bank/user-bank-record/update`, data })
  },

  // 删除用户-题库-记录
  deleteUserBankRecord: async (id: number) => {
    return await request.delete({ url: `/exam/user-bank/user-bank-record/delete?id=` + id })
  },

  // 获得用户-题库-记录
  getUserBankRecord: async (id: number) => {
    return await request.get({ url: `/exam/user-bank/user-bank-record/get?id=` + id })
  }
}
